﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevComponents.DotNetBar;
using AppManagement.Repositories;
using AppManagement.Helpers;
using AppManagement.Models;

namespace AppManagement.MainManagers
{
    public partial class FrmDanhSachChuyenNganh : DevComponents.DotNetBar.Office2007Form
    {
        public EventHandler Handler { get; set; }
        private DevComponents.DotNetBar.Controls.TextBoxX txtMaKhoa;

        public FrmDanhSachChuyenNganh()
        {
            InitializeComponent();
            InitHiddenFields();
        }

        public void InitHiddenFields()
        {
            txtMaKhoa = new DevComponents.DotNetBar.Controls.TextBoxX
            {
                Name = "txtMaKhoa",
                Text = ""
            };
            txtMaKhoa.Visible = false;
        }

        private void btnChonKhoa_Click(object sender, EventArgs e)
        {
            FrmQuanLyKhoa frm = new FrmQuanLyKhoa(true);
            frm.Handler += GetKhoa;
            frm.ShowDialog();
        }

        public void GetKhoa(object sender, EventArgs e)
        {
            var eventType = (TransferSimpleDataEvent)e;
            string[] comp = eventType.Data.Split(new char[] { '#' });
            txtMaKhoa.Text = comp[0];
            txtKhoa.Text = comp[1];

            var lstChuyenNganh = ChuyenNganhRepository.SelectByMaKhoa(int.Parse(txtMaKhoa.Text));
            cbxChuyenNganh.Items.Clear();
            foreach (var item in lstChuyenNganh)
            {
                cbxChuyenNganh.Items.Add(item);
            }
            if (cbxChuyenNganh.Items.Count > 0)
            {
                cbxChuyenNganh.SelectedIndex = 0;
            }
        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void btnSelect_Click(object sender, EventArgs e)
        {
            FrmQuanLyKeHoachDaoTao frm = new FrmQuanLyKeHoachDaoTao(((ChuyenNganh)cbxChuyenNganh.SelectedItem).MaCN);
            frm.ShowDialog();
        }

    }
}